package com.xinjiang.electricpower.timer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.InputStream;

/**
 * @Author D_TZ
 * @Date 2023/2/2410:55
 * @ClassName NewClothesWorkOrderTask
 * @Desription 营销配置定时任务同步
 **/
@Component
@Slf4j
public class NewClothesWorkOrderTask {

    /**
     * 执行闭环采集计量文件
     *
     * @return
     */
//    @Async
    @Scheduled(cron = "0 0 0 ? * *")  //每天00:00
    public void bhCjjlWorkOrderKjb() {
        try {
            log.info("同步闭环采集计量定时任务开启~~~~");
            InputStream in = this.getClass().getClassLoader().getResourceAsStream("bihuan/cjjl_order_general.ktr");
            //执行对应ktr 文件转换
            KettleQuartz.runKettleTransfer(null, KettleQuartz.CJ_BH, in);
            log.info("同步闭环采集计量定时任务结束~~~~");
            //Thread.sleep(800);
            this.bhCjxqWorkOrderKjb();
            this.bhGdczWorkOrderKjb();
            this.bhSbzrWorkOrderKjb();
            this.bhConfigWorkOrderKjb();
        } catch (Exception e) {
            log.error("拉取{}工单数据异常 {}", e);
        }
    }
    /**
     * 执行闭环采集消缺kjb文件
     *
     * @return
     */
//    @Async
    @Scheduled(cron = "0 0 1 ? * *")  //每天01:00
    public void bhCjxqWorkOrderKjb() {
        try {
            log.info("同步闭环采集消缺定时任务开启~~~~");
            InputStream in = this.getClass().getClassLoader().getResourceAsStream("bihuan/cjxq_order_general.ktr");
            //执行对应ktr 文件转换
            KettleQuartz.runKettleTransfer(null, KettleQuartz.CJ_BH, in);
            log.info("同步闭环采集消缺定时任务结束~~~~");
            //Thread.sleep(500);
        } catch (Exception e) {
            log.error("拉取{}工单数据异常 {}", e);
        }
    }
    /**
     * 执行闭环工单充值kjb文件
     *
     * @return
     */
//    @Async
    @Scheduled(cron = "0 0 2 ? * *")  //每天02:00
    public void bhGdczWorkOrderKjb() {
        try {
            log.info("同步执行闭环工单充值数定时任务开启~~~~");
            InputStream in = this.getClass().getClassLoader().getResourceAsStream("bihuan/gdcz_order_general.ktr");
            //执行对应ktr 文件转换
            KettleQuartz.runKettleTransfer(null, KettleQuartz.CJ_BH, in);
            log.info("同步执行闭环工单充值数定时任务结束~~~~");
            //Thread.sleep(600);
        } catch (Exception e) {
            log.error("拉取{}工单数据异常 {}", e);
        }
    }
    /**
     * 执行闭环设备主任kjb文件
     *
     * @return
     */
//    @Async
    @Scheduled(cron = "0 0 4 ? * *")  //每天凌晨11执行一次
    public void bhSbzrWorkOrderKjb() {
        try {
            log.info("同步执行[闭环设备主任]定时任务开启~~~~");
            InputStream in = this.getClass().getClassLoader().getResourceAsStream("bihuan/sbzr_order_general.ktr");
            //执行对应ktr 文件转换
            KettleQuartz.runKettleTransfer(null, KettleQuartz.CJ_BH, in);
            //Thread.sleep(900);
            log.info("同步执行[闭环设备主任]定时任务结束~~~~");
        } catch (Exception e) {
            log.error("拉取{}工单数据异常 {}", e);
        }
    }
    /**
     * 执行闭环配置参数kjb文件
     *
     * @return
     */
//    @Async
    @Scheduled(cron = "0 40 4 ? * *")
    public void bhConfigWorkOrderKjb() {
        try {
            log.info("同步执行闭环[配置参数]定时任务开启~~~~");
            InputStream in = this.getClass().getClassLoader().getResourceAsStream("bihuan/bh_all_config.ktr");
            //执行对应ktr 文件转换
            KettleQuartz.runKettleTransfer(null, KettleQuartz.CJ_BH, in);
            //Thread.sleep(1000);
            log.info("同步执行闭环[配置参数]数定时任务结束~~~~");
        } catch (Exception e) {
            log.error("拉取{}工单数据异常 {}", e);
        }
    }
    /**
     * 执行所有营销数据kjb文件
     *
     * @return
     */
//    @Async
    @Scheduled(cron = "0 0 3 * * ?")  //每天凌晨3点执行
    public void yxConfigWorkOrderKjb() {
        try {
            log.info("执行所有营销数据kjb文件定时任务开启~~~~");
            InputStream in = this.getClass().getClassLoader().getResourceAsStream("kettle/yx_all_order_general.ktr");
            //执行对应ktr 文件转换
            KettleQuartz.runKettleTransfer(null, KettleQuartz.YIN_XIAO, in);
            //Thread.sleep(1000);
            log.info("执行所有营销数据kjb文件数定时任务结束~~~~");
        } catch (Exception e) {
            log.error("拉取{}工单数据异常 {}", e);
        }
    }
    /**
     * 执行营销配置kjb文件
     *
     * @return
     */
//    @Async
    @Scheduled(cron = "0 30 8 ? * *")  //每天早上8:20执行一次
    public void runWorkOrderKjb() {
        try {
            log.info("同步营销配置参数定时任务开启~~~~");
            InputStream in = this.getClass().getClassLoader().getResourceAsStream("kettle/yinxiao-config.ktr");
            //执行对应ktr 文件转换
            KettleQuartz.runKettleTransfer(null, KettleQuartz.YIN_XIAO, in);
            log.info("同步营销配置参数定时任务结束~~~~");
            //Thread.sleep(900);
        } catch (Exception e) {
            log.error("拉取{}工单数据异常 {}", e);
        }
    }
}
